package com.example.myapplication;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;

public class photoAdapter extends BaseAdapter {
    Context context;
    String []arr;

    public photoAdapter(Context context, String[] arr) {
        this.context = context;
        this.arr = arr;
        //111
    }

    @Override
    public int getCount() {
        return  arr.length;
    }

    @Override
    public Object getItem(int position) {
        return arr[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView==null)
        {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_photo, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder =(ViewHolder) convertView.getTag();
        }
        //使用框架加载网络图片
        Picasso.with(context).load(arr[position]).into(holder.iv);
        return convertView;
    }

    class ViewHolder {
        ImageView iv;
        public ViewHolder(View view){
            iv = view.findViewById(R.id.item_iv);
        }
    }
}
